﻿using System.Threading;
using System.Threading.Tasks;
using Mediator;

namespace Iot.Shared.PublishStrategies;

public class ParallelNoWaitPublisher : INotificationPublisher
{
    public ValueTask Publish<TNotification>(NotificationHandlers<TNotification> handlers, TNotification notification,
        CancellationToken cancellationToken) where TNotification : INotification
    {
        foreach (var handler in handlers)
            Task.Run(() => handler.Handle(notification, cancellationToken), cancellationToken);
        return ValueTask.CompletedTask;
    }
}